package com.aishang.javacv.lab.endpoint;

import com.aishang.javacv.lab.entity.VideoAddr;
import com.aishang.javacv.lab.executor.VideoPushExecutor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/videoPusher")
public class PushVideoHandler {
    @Resource
    VideoPushExecutor videoPushExecutor;

    /**
     * 开启拉流，推流
     * @return
     */
    @GetMapping("/start")
    public String start(){
        videoPushExecutor.start();
        return "成功了！";
    }

    /**
     * 关闭推流，拉流
     * @return
     */
    @GetMapping("/stop")
    public String stop(@RequestParam(required = false) String from){
        videoPushExecutor.stop(from);
        return "成功了！";
    }

    /**
     * 重启
     * @return
     */
    @GetMapping("/restart")
    public String restart(){
        videoPushExecutor.restart();
        return "成功了！";
    }

    /**
     * 添加配置
     * @return
     */
    @PostMapping("/add")
    public String add(@RequestBody VideoAddr videoAddr){
        videoPushExecutor.add(videoAddr);
        return "成功了！";
    }

    /**
     * 修改配置
     * @return
     */
    @PutMapping("/update")
    public String update(@RequestBody VideoAddr videoAddr){
        videoPushExecutor.update(videoAddr);
        return "成功了！";
    }

    /**
     * 查看列表
     * @return
     */
    @GetMapping("/videoList")
    public List<VideoAddr> getList(){
        return videoPushExecutor.getList();
    }

    /**
     * 删除video信息
     * @return
     */
    @GetMapping("/delete")
    public List<VideoAddr> delete(@RequestParam Long id){
        return videoPushExecutor.delete(id);
    }
}
